-- Written and tested in Lua 5.3.0 for Mac OS
-- http://www.lua.org/ftp/lua-5.3.0.tar.gz

-- Set map size here
xsize = 92
ysize = 46

-- Set # of breaks ( lines of ocean vs land)
breaks = math.floor( ( ( xsize / 6 ) + ( ysize / 6 ) ) / 2 )

terrain_layer = {}
zeroPad = "0000"
math.randomseed( ( '' .. os.time() ):reverse() )

for y = 0, ysize - 1, 1 do

	terrain_layer[ y ] = ""

	for x = 0, xsize - 1, 1 do

		local terrain = ""
		local z = math.random( 1, 74 )

		if     z >=  1 and z<= 30 then terrain = "g"
		elseif z >= 31 and z<= 61 then terrain = "p"
		elseif z >= 62 and z<= 65 then terrain = "f"
		elseif z >= 66 and z<= 70 then terrain = "h"
		elseif z == 71 then terrain = "j"
		elseif z == 72 then terrain = "s"
		elseif z == 73 then terrain = "d"
		elseif z == 74 then terrain = "m"
		end


		if x >= 0 and x % breaks >= 0 and x % breaks < 4 then
			terrain=" "
		end

		if y >= 0 and y % breaks >= 0 and y % breaks < 4 then
			terrain=" "
		end

		terrain_layer[ y ] = terrain_layer[ y ] .. terrain
	end

	print( "t" .. string.sub( zeroPad, 1, string.len( zeroPad ) - string.len( y ) )
		.. y .. "=\"" .. terrain_layer[ y ] .. "\"" )
end

-- output blank startpos info
print( 'startpos_count=0\nstartpos={"x","y","exclude","nations"\n}' )

-- output the "e" layers
layers = { "e00_", "e01_", "e02_", "e03_" }
for i = 1, #layers, 1 do
	for y = 0, ysize - 1, 1 do
		print( layers[ i ] .. string.sub( zeroPad, 1, string.len( zeroPad ) - string.len( y ) )
			.. y .. "=\"" .. string.rep( "0", xsize ) .. "\"" )
	end
end

-- output the "res" layer
for y = 0, ysize - 1, 1 do
	print( "res" .. string.sub( zeroPad, 1, string.len( zeroPad ) - string.len( y ) )
		.. y .. "=\"" .. string.rep( " ", xsize ) .. "\"" )
end

